package com.lancoo.znbkxx.teacher.diagnosis

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.model.data.ZsdArea
import kotlinx.android.synthetic.main.item_zsdarea.view.*

/**
 *@author Admin
 *@date 2020/12/29
 *
 */
class ZsdAreaAdapter(data: List<ZsdArea>, val listener: OnSelectListener) :
        BaseQuickAdapter<ZsdArea, BaseViewHolder>(data) {
    init {
        mLayoutResId = R.layout.item_zsdarea
    }

    override fun convert(helper: BaseViewHolder, item: ZsdArea?) {
        with(helper.itemView) {
            tv_name.text = item!!.Name
            tv_child.text = item.FirstExplain
            tv_sub.text = item.SccondExplain
            cb.isClickable = !item.Checked
            cb.setOnCheckedChangeListener { _, isChecked ->
                if (isChecked) {
                    data.forEach {
                        it.Checked = false
                    }
                    item.Checked = isChecked
                    listener.onSelect(helper.layoutPosition)
                }
                postDelayed({
                    notifyDataSetChanged()
                }, 10)
            }
            cb.isChecked = item.Checked
        }
    }

    interface OnSelectListener {
        fun onSelect(layoutPosition: Int)
    }
}